/**
 * @program: leetcode011
 * @author: JCM
 * @create: 2022-11-20 19:40
 * @description:
 **/
public class leetCode011 {
    //暴力枚举
    public int maxArea1(int[] height) {
        int ans = 0;
        int maxleft = 0;
        for(int i = 0; i < height.length-1; i++) {
            if(maxleft >= height[i]) {
                continue;
            }else {
                maxleft = height[i];
            }
            for(int j = i+1; j < height.length; j++) {
                int area = Math.min(height[i],height[j])*(j-i);
                ans = Math.max(ans,area);
            }
        }
        return ans;
    }

    /**
     * 递归
     * 时间复杂度：O(N)
     * 空间复杂度：O(1)
     * @param height
     * @return
     */
    public int maxArea(int[] height) {
        int i = 0, j = height.length-1, res = 0;
        while(i < j) {
            res = height[i] < height[j] ?
                    Math.max(res,(j-i)*height[i++]) : Math.max(res,(j-i)*height[j--]);
        }
        return res;
    }

}
